package com.archermind.amosp;

import java.util.List;

import DataManager.DataManager;
import DataManager.MenuInfo;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView.RecyclerListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class AmospOrderAdapter extends BaseAdapter implements RecyclerListener {
    
	private Context mContext;
	private List<MenuInfo> mListItem;
	private DataManager mDataManager;
	public AmospOrderAdapter(Context context,List<MenuInfo> items){
		mContext = context;
		mListItem = items;
		mDataManager = ((AmospOrderFoodActivity)mContext).getDataManager();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mListItem.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mListItem.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return mListItem.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		ViewHolder hold;
        if (convertView == null) {
            convertView = ((Activity)mContext).getLayoutInflater().inflate(R.layout.amosp_order_list_item,
                    parent, false);
            hold = new ViewHolder();
            hold.text = (TextView)convertView.findViewById(R.id.item_name);
            hold.iconAdd = (ImageButton)convertView.findViewById(R.id.item_add);
            hold.iconDelete = (ImageButton)convertView.findViewById(R.id.item_delete);
            convertView.setTag(hold);
        }else{
        	hold = (ViewHolder)convertView.getTag();
        }
        hold.text.setText(mListItem.get(position).getName());
        hold.iconAdd.setOnClickListener(new ImageButtonAddListener(position));
        hold.iconDelete.setOnClickListener(new ImageButtonDeleteListener(position));
//        updateDeleteBtnStatus(position);
        return convertView;
    }
	
	@Override
	public void onMovedToScrapHeap(View arg0) {
		// TODO Auto-generated method stub
		
	}
	
	
    static class ViewHolder {
        TextView text;
        ImageButton iconAdd;
        ImageButton iconDelete;
    }
	
    class ImageButtonAddListener implements OnClickListener{
		int mPos;
		ImageButtonAddListener(int postion){
            mPos = postion;	
        }
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			mDataManager.addOrderInfo(mPos,mListItem.get(mPos).getName());
		}
    }
    
    class ImageButtonDeleteListener implements OnClickListener{
		int mPos;
		ImageButtonDeleteListener(int postion){
            mPos = postion;	
        }
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
		}
    }

}
